app.service('advertisementService',['$q','utilService',function($q,utilService){

    //查询广告分类下拉框
    this.getList = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'advertise/type/list'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }
    //查询ById
    this.findById = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'advertise/'+ $scope.advertise.id,
            params:{id:$scope.advertise.id}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }
    //删除广告
    this.delAdvertise = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'advertise/del',
            data:{id:$scope.advertise.id},
            method:"PUT"
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
    //新增广告
    this.addAdvertise = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'advertise',
            data:$scope.advertise,
            method:'POST'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
    //修改广告
    this.editAdvertise = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'advertise',
            data:$scope.advertise,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
    //删除广告图片信息
    this.delAdvertisePic=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'advertise/pic',
            data:$scope.advertise,
            method:'DELETE'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    };
    //禁用启用
    this.changeStatus = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'advertise/change/status',
            data:{id:$scope.advertise.id},
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
}]);

/*上传图片Service*/
app.service('fileUploadService',['$q','utilService',function($q,utilService){
    var _this_=this;
    _this_.del=function($scope,item){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'upload/',
            data:{filefullPath:item.fileName},
            method:'DELETE'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
}])